/**
 * Created by chengcong on 2017/12/7.
 */
var url='http://120.27.161.98:6655'
$(function () {
    $.ajax({
        url:url+'/api/WebPage/GetNewsList',
        type:'post',
        data:{classid:"11",pageIndex:"1",pageSize:"4",OrderBy:"",SortOrder:""},
        success:function (data) {
            console.log(data);
            $('.newscontent').html('');
            if(data.code==200){
                for(var i=0;i<data.data.List.length;i++){
                    if(data.data.List[i].photo==''){data.data.List[i].photo='../img/news1.jpg'}else{
                        data.data.List[i].photo='http://120.27.161.98:6677/'+data.data.List[i].photo
                    };
                    if(i%2>0){
                        $('.newscontent').append('<div class="col-xs-6 skk-a">' +
                            '<div class="news-as clearfix">' +
                            '<a href="javascript:void(0)">' +
                            '<div class="news-as-a"  detailid="'+data.data.List[i].id+'">' +
                            '<img src="'+data.data.List[i].photo+'" height="100px" alt="..."  detailid="'+data.data.List[i].id+'">' +
                            '</div>' +
                            '<div class="news-as-b"  detailid="'+data.data.List[i].id+'">' +
                            '<h2  detailid="'+data.data.List[i].id+'">'+data.data.List[i].title+'</h2>' +
                            '<p detailid="'+data.data.List[i].id+'">'+data.data.List[i].info+'</p>' +
                            '</div>' +
                            '<div class="news-as-c">' +
                            '<p>' +
                            '<strong class="pyogg">' +
                            '<img style="width:25px;margin-right:5px;" src="../img/phone-wx-news.png" alt="...">' +
                            '<img style="width:25px;" src="../img/phone-xl-news.png" alt="...">' +
                            '</strong>' +
                            '</p>' +
                            '</div>' +
                            '</a>' +
                            '</div>' +
                            '</div>')
                    }else{
                        $('.newscontent').append('<div class="col-xs-6 skk-a skk-b">' +
                            '<div class="news-as clearfix">' +
                            '<a href="javascript:void(0)">' +
                            '<div class="news-as-a"  detailid="'+data.data.List[i].id+'">' +
                            '<img src="'+data.data.List[i].photo+'" height="100px" alt="..."  detailid="'+data.data.List[i].id+'">' +
                            '</div>' +
                            '<div class="news-as-b"  detailid="'+data.data.List[i].id+'">' +
                            '<h2  detailid="'+data.data.List[i].id+'">'+data.data.List[i].title+'</h2>' +
                            '<p detailid="'+data.data.List[i].id+'">'+data.data.List[i].info+'</p>' +
                            '</div>' +
                            '<div class="news-as-c">' +
                            '<p>' +
                            '<strong class="pyogg">' +
                            '<img style="width:25px; margin-right:5px;" src="../img/phone-wx-news.png" alt="...">' +
                            '<img style="width:25px;" src="../img/phone-xl-news.png" alt="...">' +
                            '</strong>' +
                            '</p>' +
                            '</div>' +
                            '</a>' +
                            '</div>' +
                            '</div>')
                    }
                }
                $('.news-as-a').on('click',function (e) {
                    self.location='articleContent.html?11='+$(e.target).attr('detailid')
                })
                $('.news-as-b').on('click',function (e) {
                    self.location='articleContent.html?11='+$(e.target).attr('detailid')
                })
            }
        }
    });
})
$('.submit').on('click', function () {
    if($('textarea').val()==''||$('#userphone').val()==''||$('#username').val()==''){
        alert('请完善必填信息');
    }else{
        var pattern=/(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        if(pattern.test($('#userphone').val())) {
            $.ajax({
                url: url + '/api/WebPage/AddMess',
                type: 'POST',

                data: {
                    MessContent: $('textarea').val(),
                    MessPhone: $('#userphone').val(),
                    MessUserName: $('#username').val(),
                    classid: "16"
                },
                success: function (data) {
                    console.log(data);
                    if (data.code == 200) {
                        alert('留言成功')
                        $('textarea').val('');
                        $('#userphone').val('');
                        $('#username').val('');
                    } else {
                        alert(data.mes);
                    }
                }
            })
        }else{
            alert('请输入正确的号码！');
        }
    }
});
$('#special-table2 a').on('click',function () {
    $(this).addClass('adv1-active');
    $(this).parent().parent().siblings().children().children().removeClass('adv1-active');
    $(this).parent().siblings().children().removeClass('adv1-active');
});



